﻿using System.Drawing;
using System.Windows.Forms;

namespace KD.Sms.UI
{
    public partial class KdRunStop : UserControl
    {


        private ControlStyle _stype = ControlStyle.Circular;
        private TwoStateValue _State = TwoStateValue.On;
        private DisplayStyle _Stype = DisplayStyle.Small;


        public KdRunStop()
        {
            InitializeComponent();

            _stype = ControlStyle.Circular;
            _State = TwoStateValue.On;
            _Stype = DisplayStyle.Small;

            DoSetImage();
            DoSetControl();
        }


        /// <summary>
        /// 显示文本
        /// </summary>
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("Text")]
        [System.ComponentModel.Description("显示文本")]
        [System.ComponentModel.DefaultValue("")]//默认值
        public string C_Text
        {
            set { labText.Text = value; }
            get { return labText.Text; }
        }

        /// <summary>
        /// 显示图形样式
        /// </summary>
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("Style")]
        [System.ComponentModel.Description("显示样式")]
        [System.ComponentModel.DefaultValue("")]//默认值
        public ControlStyle C_ImageStype
        {
            set
            {
                _stype = value;
                DoSetImage();
            }
            get
            {
                return _stype;
            }
        }


        /// <summary>
        /// 显示样式
        /// </summary>
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("Style")]
        [System.ComponentModel.Description("显示样式")]
        [System.ComponentModel.DefaultValue("")]//默认值
        public DisplayStyle C_Display
        {
            set
            {
                _Stype = value;
                DoSetControl();
            }
            get
            {
                return _Stype;
            }
        }

        /// <summary>
        /// 显示状态
        /// </summary>
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("Value")]
        [System.ComponentModel.Description("运行状态")]
        [System.ComponentModel.DefaultValue("")]//默认值
        public TwoStateValue C_Value
        {
            set
            {
                _State = value;
                DoSetImage();
            }
            get
            {
                return _State;
            }
        }

        private TwoStateValue C_Last { set; get; }
        private ControlStyle S_Last { set; get; }

        private void DoSetControl()
        {
            switch (_Stype)
            {
                case DisplayStyle.Small:
                    labText.Font = new Font("微软雅黑", 12, labText.Font.Style);
                    pbMain.Width = 24;
                    pbMain.Height = 24;
                    this.Width = 165;
                    this.Height = 24;
                    break;
                case DisplayStyle.Middle:
                    labText.Font = new Font("微软雅黑", 14, labText.Font.Style);
                    pbMain.Width = 32;
                    pbMain.Height = 32;
                    this.Width = 200;
                    this.Height = 32;
                    break;
                case DisplayStyle.Large:
                    labText.Font = new Font("微软雅黑", 17, labText.Font.Style);
                    pbMain.Width = 36;
                    pbMain.Height = 36;
                    this.Width = 230;
                    this.Height = 36;
                    break;
                default:
                    labText.Font = new Font("微软雅黑", 11, labText.Font.Style);
                    pbMain.Width = 32;
                    pbMain.Height = 32;
                    this.Width = 155;
                    this.Height = 32;
                    break;
            }
        }

        private void DoSetImage()
        {
            if (C_Value != C_Last || C_ImageStype != S_Last)
            {
                if (C_ImageStype == ControlStyle.Circular)
                {
                    if (C_Value == TwoStateValue.On)
                        FormHelper.SetGroundImage(pbMain, KD.Sms.UI.Properties.Resources.open);
                    else
                        FormHelper.SetGroundImage(pbMain, KD.Sms.UI.Properties.Resources.stop);
                }
                else
                {
                    if (C_Value == TwoStateValue.On)
                        FormHelper.SetGroundImage(pbMain, KD.Sms.UI.Properties.Resources.open);
                    else
                        FormHelper.SetGroundImage(pbMain, KD.Sms.UI.Properties.Resources.close);
                }
                C_Last = C_Value;
                S_Last = C_ImageStype;
            }
        }


    }
}
